package ai.people.platform.archives.ws.context;

import ai.people.netmon.framework.exception.enums.WebSocketExceptionEnum;
import ai.people.netmon.framework.utils.AssertUtils;
import ai.people.platform.archives.ws.executor.WebSocketExecutor;
import com.google.common.collect.Maps;

import java.util.Map;

/**
 * @author LiGuanNan
 * @date 2022/7/7 10:27
 */
public class WsExecutorContext {

    private static final Map<String, WebSocketExecutor> EXECUTOR_MAP = Maps.newConcurrentMap();

    public static void addWebSocketExecutor(String key, WebSocketExecutor webSocketExecutor){
        EXECUTOR_MAP.putIfAbsent(key, webSocketExecutor);
    }

    public static WebSocketExecutor getWebSocketExecutorByTag(String tag){
        WebSocketExecutor webSocketExecutor = EXECUTOR_MAP.get(tag);
        AssertUtils.isNotNull(webSocketExecutor, WebSocketExceptionEnum.ILLEGAL_TAG);
        return webSocketExecutor;
    }
}
